<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/icon.css" rel="stylesheet">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<script	src="${pageContext.request.contextPath}/js/jquery.backstretch.js"></script>
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
<title>Insert title here</title>
</head>
<script type="text/javascript">
  // close a window  

$(function(){
	
	//配置表格
	    $('#tb').datagrid({    
	    	 url:'${pageContext.request.contextPath}/findDept',    
		    columns:[[   
               
		        {field:'dept_id',title:'部门id',width:100,hidden:true},   
		        {field : 'checked',checkbox : true,width : 100},
		        {field:'dept_name',title:'部门名字',width:362},    
		        {field:'dept_describe',title:'部门描述',width:362}, 
		        {field:'dept_temp',title:'temp',hidden:true,width:100}, 
		        {field:'dept_createtime',title:'创建时间',width:362}, 
		        {field:'dept_isdel',title:'是否删除',width:100,hidden:true,align:'right'}    
		    ]],
		    onLoadError: function(){
		    	 $.messager.alert('提示','没有符合条件的搜索结果！');
	        },
		     striped:true,
	         pagination:true,
	         toolbar : [ {
					iconCls : 'icon-remove',
					text : '删除',
					handler : function() {
						var depts = $("#tb").datagrid('getSelections');
						var dept = new Array(depts.length);
						for(var i=0;i<depts.length;i++){				
							dept[i]=depts[i].dept_id;
						}
						
						if (depts.length ==0) {
							$.messager.confirm('提示', '请至少选择一条数据');
							}
						else{
							$.messager.confirm('提示', '确定删除'+depts.length+"条数据？",function(r){    
							    if (r){
							    	 $.ajax({
							  		   type:'post',
							  		   //需要发起的请求
							  		   url:'${pageContext.request.contextPath}/daleteDept',
							  		   //需要带什么数据过去
							  		   data:{'dept_id':dept},
							  		   dataType:"text",
							  		   success:function(data){ 
							  			    if(data =="1"){
							  			    	 $.messager.alert('提示','删除成功');
							  			    }else if(data=="2"){
							  			    	$.messager.alert('提示',"选中的部门还有员工未删除，请删除员工再进行操作");
							  			    	
							  			    }   
							  		       }
							  		   })
							    }; 
							$('#tb').datagrid('reload');
						})
						
					}
				},
	         }]
	         
	 });
		 //配置搜索框
		 $('#searchBox').searchbox({ 
			 searcher:function(value,name){ 
				 var dept_name = value;
				 
			  		$('#tb').datagrid('reload',{
			  			searchname:dept_name,
			  			
			  		});
			      }, 
			 });
		
		 
		


});      




</script>
<body>
     <input id="searchBox" type="hidden">
     <h2 align="center"style="color:#FFFFFF">部门信息表</h2>
     <table id="tb" ></table> 
     
    

     
</body>
</html>